<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="试卷名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入试卷名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用类型" prop="userType">
        <el-select
          v-model="queryParams.userType"
          placeholder="请输入使用类型"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in options.USER_TYPE.list"
            v-bind="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="试卷类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请输入试卷类型"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in options.TEST_PAPER_TYPE.list"
            v-bind="item"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="及格分数" prop="passGrade">
        <el-input-number
          :min='0'
          :controls="false"
          v-model="queryParams.passGrade"
          placeholder="请输入及格分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总分数" prop="totalGrade">
        <el-input-number
          :min='0'
          :controls="false"
          v-model="queryParams.totalGrade"
          placeholder="请输入总分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <dept-selector
          v-model="queryParams.deptId"
          placeholder="请输入部门"
          clearable
          @keyup.enter.native="handleQuery"
        >
        </dept-selector>
      </el-form-item>
      <el-form-item label="岗位" prop="postId">
        <el-select
          v-model="queryParams.postId"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in options.postList"
            :label="item.postName"
            :value="item.postId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="岗位级别" prop="postLevelCode">
        <el-select
          v-model="queryParams.postLevelCode"
          placeholder="请输入能力级别"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.post_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"

        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"

        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"

        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"

        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="ExamTestPaperModuleList" @selection-change="handleSelectionChange">
      <el-table-column resizable show-overflow-tooltip type="selection" width="55" align="center"/>
      <el-table-column resizable show-overflow-tooltip label="试卷名称" align="center" prop="name"/>
      <el-table-column resizable show-overflow-tooltip label="使用类型" align="center" prop="userType">
        <template #default="{row}">
          {{ options.USER_TYPE.map[row.userType] }}
        </template>
      </el-table-column>
      <el-table-column resizable show-overflow-tooltip label="试卷类型" align="center" prop="type">
        <template #default="{row}">
          {{ options.TEST_PAPER_TYPE.map[row.userType] }}
        </template>
      </el-table-column>
      <el-table-column resizable show-overflow-tooltip label="及格分数" align="center" prop="passGrade"/>
      <el-table-column resizable show-overflow-tooltip label="总分数" align="center" prop="totalGrade"/>
      <el-table-column resizable show-overflow-tooltip label="部门" align="center" prop="deptId">
        <template #default="{row}">
          {{ row.deptId | deptFilter }}
        </template>
      </el-table-column>
      <el-table-column resizable show-overflow-tooltip label="岗位" align="center" prop="postId">
        <template #default="{row}">
          {{ row.postId | postFilter }}
        </template>
      </el-table-column>
      <el-table-column resizable show-overflow-tooltip label="岗位级别" align="center" prop="postLevelCode">
        <template #default="{row}">
          <dict-tag :options="dict.type.post_level" :value="row.postLevelCode"/>
        </template>
      </el-table-column>
      <el-table-column resizable show-overflow-tooltip label="备注" align="center" prop="remark"/>
      <el-table-column resizable label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"

          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"

          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改试卷模板对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="试卷名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入试卷名称" style="width: 320px" clearale/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="使用类型" prop="userType">
              <el-select v-model="form.userType" placeholder="请输入使用类型" style="width: 320px" clearale>
                <el-option
                  v-for="item in options.USER_TYPE.list"
                  v-bind="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="试卷类型" prop="type">
              <el-select v-model="form.type" placeholder="请输入试卷类型" style="width: 320px" clearale>
                <el-option
                  v-for="item in options.TEST_PAPER_TYPE.list"
                  v-bind="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门" prop="deptId">
              <dept-selector v-model="form.deptId" placeholder="请输入部门" style="width: 320px" clearale>
              </dept-selector>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="岗位" prop="postId">
              <post-selector v-model="form.postId" placeholder="请输入岗位" style="width: 320px" clearale>
              </post-selector>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="岗位级别" prop="postLevelCode">
              <el-select
                v-model="form.postLevelCode" placeholder="请输入岗位级别" style="width: 320px" clearale
              >
                <el-option
                  v-for="dict in dict.type.post_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="及格分数" prop="passGrade">
              <el-input-number :min='0' :controls='false' v-model="form.passGrade" placeholder="请输入及格分数"
                               style="width: 320px"
                               clearale/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总分数" prop="totalGrade">
              <el-input-number :min='0' :controls='false' v-model="form.totalGrade" placeholder="请输入总分数"
                               style="width: 320px"
                               clearale/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 12}" placeholder="请输入内容" style="width: 320px" clearale/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">
          试题抽取规则信息<i class="el-icon-question" title="将会从以下规则中抽取题目"></i>
        </el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddExamTestPaperExtractRule">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteExamTestPaperExtractRule">
              删除
            </el-button>
          </el-col>
        </el-row>
        <el-table border :data="examTestPaperExtractRuleList" :row-class-name="rowIndex"
                  @selection-change="handleExamTestPaperExtractRuleSelectionChange" ref="examTestPaperExtractRule"
                  @row-click="handleExtractRuleRowClick">
          <el-table-column resizable show-overflow-tooltip type="selection" width="50" align="center"/>
          <el-table-column resizable show-overflow-tooltip label="序号" align="center" prop="index" width="50"/>
          <el-table-column resizable show-overflow-tooltip label="抽取试题的类型" prop="questionType" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.questionType" placeholder="类型" @click.stop="noop">
                <el-option
                  v-for="item in options.QUESTION_TYPE.list"
                  v-bind="item"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="分数" prop="grade" width="100">
            <template slot="header" slot-scope="scope">
              分数<i class="el-icon-question" title="抽取的试题每个的分数"></i>
            </template>
            <template slot-scope="scope">
              <el-input-number :min='0' :controls="false" v-model="scope.row.grade" placeholder="分数"
                               style="width: 100%" @click.stop="noop"/>
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="抽取数量" prop="number" width="100">
            <template slot-scope="scope">
              <el-input-number :min='0' :controls="false" v-model="scope.row.number" placeholder="数量"
                               style="width: 100%" @click.self="noop"/>
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="大纲" prop="syllabusCode" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.syllabusCode" placeholder="大纲" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.syllabus"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="岗位级别" prop="syllabusCode" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.postLevelCode" :ref="`postLevelCodeSelector-${scope.$index}`"
                         placeholder="岗位级别" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.post_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
<!--                <el-option-->
<!--                  v-for="level in options.rulePostLevel"-->
<!--                  :key="level.value"-->
<!--                  :label="level.label"-->
<!--                  :value="level.value"-->
<!--                />-->
              </el-select>
            </template>
          </el-table-column>

          <el-table-column resizable show-overflow-tooltip label="知识点" prop="knowledgePointId" width="520">
            <template slot-scope="scope">
              <post-subject-point-cascader
                ref="postSubjectPointCascader"
                v-model="scope.row.knowledgePointId"
                placeholder="知识点"
                :options="postSubjectPointTree"
                @change="handleKnowledgePointsChange(scope.row)"
                style="width: 100%"
              />
            </template>
          </el-table-column>
        </el-table>
        <el-divider content-position="center">试题固定题目</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddExamTestRequired">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteExamTestRequired">
              删除
            </el-button>
          </el-col>
        </el-row>
        <el-table border :data="requiredExamList" @selection-change="handleRequiredExamSelectionChange" ref="examRequiredExam"
                  :row-class-name="rowIndex" @row-click.self="handleRequiredExamRowClick">
          <el-table-column resizable show-overflow-tooltip type="selection" width="55" align="center"/>
          <el-table-column resizable show-overflow-tooltip type="index"></el-table-column>
          <el-table-column resizable show-overflow-tooltip label="考题编码" align="center" prop="code"/>
          <el-table-column resizable show-overflow-tooltip label="部门" align="center" prop="deptId">
            <template v-slot="{row}">
              {{ row.deptId | deptFilter }}
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="大纲" align="center" prop="syllabusCode">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.syllabus" :value="scope.row.syllabusCode"/>
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="岗位" align="center" prop="postId">
            <template slot-scope="{row}">
              {{ row.postId | postFilter }}
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="科目" align="center" prop="subjectName"/>
          <el-table-column resizable show-overflow-tooltip label="知识点" align="center" prop="knowledgePointsName"/>
          <el-table-column resizable show-overflow-tooltip label="考题类型" align="center" prop="questionType">
            <template v-slot="{row}">
              {{ options.QUESTION_TYPE.map[row.questionType] }}
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="题干内容" align="center" prop="content"/>
          <el-table-column resizable show-overflow-tooltip label="能力级别" align="center" prop="postLevelCode">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.post_level" :value="scope.row.postLevelCode"/>
            </template>
          </el-table-column>
          <el-table-column resizable show-overflow-tooltip label="分数" align="center" prop="postLevelCode">
            <template slot-scope="scope">
              <el-input-number :min='0' v-model="scope.row.grade" :controls="false" style="width: 80px;"/>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer
      title="选取题目"
      :visible.sync="requiredExamVisible"
      direction="rtl"
      size="70%"
    >
      <exam-question-bank :defaultSelectedIds="defaultSelectedIds" ref="requiredExamTable"
                          :defaultParams="requiredExamParams" show-params @handleConfirm="handleRequiredExamConfirm"
                          @handleCancel="handleRequiredExamCancel" class="app-container"/>
    </el-drawer>
  </div>
</template>

<script src="./index.js"></script>

